package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Override
    @Transactional
    public void fllow(ClueTrackRecordVo tbClueTrackRecord) {
        String name = SecurityUtils.getUsername();
        TbClue tbClue = new TbClue();
        tbClueTrackRecord.setType("1");
        tbClueTrackRecordMapper.save(name, tbClueTrackRecord);

        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setStatus("2");
        tbClue.setId(tbClueTrackRecord.getClueId());
        tbClueTrackRecordMapper.update(tbClue);


    }

    @Override
    public TableDataInfo getList(Long clueId) {
        List<TbClueTrackRecord> list = tbClueTrackRecordMapper.getList(clueId);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(200);
        tableDataInfo.setMsg("查询成功");
        tableDataInfo.setRows(list);
        tableDataInfo.setTotal(list.size());
        return tableDataInfo;
    }
}
